package com.ruoyi.lvlian.service.impl;

import java.util.List;

import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.MD5Utils;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.lvlian.mapper.PoundMapper;
import com.ruoyi.lvlian.domain.Pound;
import com.ruoyi.lvlian.service.IPoundService;

/**
 * 磅称管理Service业务层处理
 *
 * @author lvlian
 * @date 2025-04-24
 */
@Service
public class PoundServiceImpl implements IPoundService {
    @Autowired
    private PoundMapper poundMapper;

    /**
     * 查询磅称管理
     *
     * @param id 磅称管理主键
     * @return 磅称管理
     */
    @Override
    public Pound selectPoundById(String id) {
        return poundMapper.selectPoundById(id);
    }

    /**
     * 查询磅称管理列表
     *
     * @param pound 磅称管理
     * @return 磅称管理
     */
    @Override
    public List<Pound> selectPoundList(Pound pound) {
        return poundMapper.selectPoundList(pound);
    }

    /**
     * 新增磅称管理
     *
     * @param pound 磅称管理
     * @return 结果
     */
    @Override
    public int insertPound(Pound pound) {
        pound.setId(    MD5Utils.md5( pound.getName()  ) );
        pound.setCreateUser(SecurityUtils.getUsername());
        pound.setCreateDate(DateUtils.getCurrentTime());
        return poundMapper.insertPound(pound);
    }

    /**
     * 修改磅称管理
     *
     * @param pound 磅称管理
     * @return 结果
     */
    @Override
    public int updatePound(Pound pound) {
        int updateResult = poundMapper.updatePound(pound);
        if (0 == updateResult) {
            updateResult = insertPound(pound);
        }

        return updateResult;

    }

    /**
     * 批量删除磅称管理
     *
     * @param ids 需要删除的磅称管理主键
     * @return 结果
     */
    @Override
    public int deletePoundByIds(String[] ids) {
        return poundMapper.deletePoundByIds(ids);
    }

    /**
     * 删除磅称管理信息
     *
     * @param id 磅称管理主键
     * @return 结果
     */
    @Override
    public int deletePoundById(String id) {
        return poundMapper.deletePoundById(id);
    }
}
